<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/base.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>幸运抽奖管理</title>
<style type="text/css">
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	.p-c-flexwrapper > span {
		width:163px;
		text-align: right;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper > .form-control {
		width:168px;
	}
table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
.hidden-td {
	display:none;
}
</style>
</head>
<body>
	<div style="display:flex;"><button  class="save btn btn-primary btn-lg" >转盘基本设置</button>
	<button  class="save btn btn-primary btn-yhyjcsjj" style="margin-left: 20px;font-size: 18px;border-radius: 6px;">用户摇奖次数加减</button>
	</div>
	<table id="table-i-qqAccountList" class="table table-striped table-bordered table-hover" style="margin-top: 20px;">
		<thead>
			<tr>
				<th>用户名</th>
				<th>奖品类型</th>
				<th>中奖金额(元)</th>
				<th>中奖时间</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<div>
		<div class="modal fade" id="addAndEditModal" tabindex="-1" role="dialog" aria-labelledby="addAndEditModal" aria-hidden="true">
			<div class="modal-dialog" style="width:1000px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">修改奖品设置</h4>
					</div>
					<p style="color:red;font-weight:bold;padding-left:8px;padding-top:8px;">注：修改中奖几率时，请保证所有奖项中奖几率总和等于1，否则会出现中奖几率权重异常。</p>
					<div class="modal-body">
						<p class="p-c-flexwrapper" data-index="1"><span style="font-weight:bold;">特等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="2"><span style="font-weight:bold;">二等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="3"><span style="font-weight:bold;">三等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="4"><span style="font-weight:bold;">四等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="5"><span style="font-weight:bold;">五等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="6"><span style="font-weight:bold;">六等奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="7"><span style="font-weight:bold;">幸运奖设置</span><span>中奖几率：</span><input class="form-control lotter-percent" type="number" /><span>最大金额：</span><input class="form-control max-money" type="number" /><span>最小金额：</span><input class="form-control min-money" type="number" /></p>
						<p class="p-c-flexwrapper" data-index="8"><span style="font-weight:bold;display:inline-block;width:112px;">不中奖设置</span><span style="display:inline-block;width:112px;white-space:nowrap;">中奖几率：</span><input class="form-control lotter-percent buzhongjiang-percent" type="number" /></p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-success btn-saveAllOptions">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	
<!-- 模态框（Modal） -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            </div>
            <div class="modal-body">你确定要删除该条记录吗？</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="btn-i-delModalBtn">删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>	
	
<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>  



	
	
	<div class="modal fade" id="allNextLevelModal1" tabindex="-1" role="dialog" aria-labelledby="allNextLevelModal" aria-hidden="true" style="z-index:1050;">
    <div class="modal-dialog class-fake-alert" style="width:1000px;">
        <div class="modal-content">
            <div class="modal-header">
               	<span>用户名：</span><input class="form-control yhuming" style="width: 126px;display:inline-block" />
               	<button type="button" class="btn btn-success btn-chax" style="margin-top: -4px;border-radius: 15px;">查询</button>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" >
            		<table id="table-i-dailiList1"  class="table table-striped table-bordered table-hover">
            			<thead>
            				<tr>
            					<th>用户名称</th>
            					<th>摇奖次数</th>
            					<th>创建时间</th>
            					<th>操作</th>
            				</tr>
            			</thead>
            			<tbody>
            			</tbody>
            		</table>
            </div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>  




<!-- 减掉用户摇奖次数模态框 -->
  <div>
		<div class="modal fade" id="addAndEditModal1" tabindex="-1" role="dialog" aria-labelledby="addAndEditModal" aria-hidden="true">
			<div class="modal-dialog" style="width:1000px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">修改用户摇奖次数</h4>
					</div>
					<div class="modal-body">
						<p class="p-c-flexwrapper" ><span style="font-weight:bold;width: 199px;">用户摇奖次数修改</span><span>用户名：</span><input class="form-control yhuming" /><span>摇奖次数：</span><input class="form-control yaojiangcs" type="number" /></p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-success btn-bc">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	



	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script type="text/javascript">
		$("#table-i-qqAccountList").DataTable({
	      // "bPaginate": true,
	      "bLengthChange": true,      
	      "bSort": false,
	      // "bInfo": true,
	      "bAutoWidth": false,
//		         "bServerSide":true,
	      'aLengthMenu':[10, 20],
	       "searching": false,
	       "dom": `ftp`,
//		    "searching": true,l
	       "language": {//语言设置  
	            "lengthMenu": "每页显示 _MENU_ 条记录",     
	            "zeroRecords": "没有检索到数据",     
	            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
	            "info": "没有数据",     
	            "oPaginate": {     
	                "sFirst": "首页",     
	                "sPrevious": "前一页",     
	                "sNext": "后一页",     
	                "sLast": "尾页"    
	          	},
	            "search":"搜索:",
	            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
	            "infoEmpty":      "没有找到匹配的信息",
	         },
	         "ajax": {
	        	 "type": "POST",
	        	 "url":"/activity/getAllLuckCheck.do",
	         },
	         "columns": [
						 {"data": "name", "className": "name-edit-td"},
						 {"data": "type", "className": "type-edit-td"},
	                     {"data": "money", "className": "money-edit-td"},
	                     {"data": "createTime", "className": "createTime-edit-td"},
	                 ]        
	   		 })		
	   		$(".save.btn-lg").on("click", function(e) {
	   			//
				$.ajax({
					  url: "/activity/getAllLuckyLotter.do",
					  type: "post",
					  data: {},
					  dataType: "json",
					  success:function(data){
					  	$("[data-index]").each(function(index, element) {
					  		for (var i = 0; i < data.data.length; i++) {
					  			var dataItem = data.data[i]
					  			if (String(dataItem.id) === element.dataset.index) {
					  				var $self = $(element)
							  		var dataArr = dataItem.lotterMoney.split(",")
							  		$self.find(".min-money").val(dataArr[0])
							  		$self.find(".max-money").val(dataArr[1])
							  		$self.find(".lotter-percent").val(dataItem.rebate)
					  			}
					  		}
					  	})
			   			$("#addAndEditModal").modal("show")
					  },
				});	
	   		}) 
	   		
	   		 $("#table-i-dailiList1").DataTable({
		      "bLengthChange": true,      
		      "bAutoWidth": false,
		      "bSort": false,
		      "dom": `t<"tableToolBar" p<"lengthWrapper" l>i>`,
		      'aLengthMenu':[5, 10, 20],
		       //"order": [[ 9, "asc" ]],  
		       "searching": true,  
		       "language": {//语言设置  
		            "lengthMenu": "每页显示 _MENU_ 条记录",     
		            "zeroRecords": "没有检索到数据",     
		            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
		            "info": "没有数据",     
		            "oPaginate": {     
		                "sFirst": "首页",     
		                "sPrevious": "前一页",     
		                "sNext": "后一页",     
		                "sLast": "尾页"    
		          	},
		            "search":"搜索:",
		            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
		            "infoEmpty":      "没有找到匹配的信息",
		         }, 
		         "columns": [
		                     { "data": "name" ,"className":"name-td" },
		                     { "data": "count" ,"className":"count-td" },
		                     { "data": "createTime"},
		                     { "data": null,"defaultContent": "<button type='button' onclick='butcsxg(this)' class='btn btn-success btn-csxg'>修改</button>"},
		                     { "data": "id", "className": "td-c-id hidden-td"},
		                    
		                   ],	 
			      "ajax": {
		    	  	  "type": 'post',
		    	      "url":"/activity/findUserLuckyRecord.do",
	    	    	  "data": function(d) {
		 	        		 return d
		 	        	 },
			      },	
		       })
		       $(".btn-yhyjcsjj").on("click",function(){
	   				$("#allNextLevelModal1").modal("show")
	   				$("#table-i-dailiList").DataTable().ajax.url("/activity/findUserLuckyRecord.do").load()
	   			})
	   			function butcsxg(e){
					var name = $(e).parent().siblings(".name-td").text()
					var count = $(e).parent().siblings(".count-td").text()
					$("#addAndEditModal1").modal("show")
					$(".yhuming").val(name)
					$(".yaojiangcs").val(count)
				}
				$(".btn-chax").on("click",function(){
					var param = {name: $(".yhuming").val()};
					$("#table-i-dailiList1").DataTable().settings()[0].ajax.data = param;
					$("#table-i-dailiList1").DataTable().ajax.url("/activity/findByNameLuckyCount.do").load();
				})
	   		var doubleNumberReg = /^[0-9]+([.]{1}[0-9]{1,2})?$/
	   		var integerNumberReg = /^[0-9]+$/
	   		var transIdToStr = {
				"1": "特等奖",
				"2": "二等奖",
				"3": "三等奖",
				"4": "四等奖",
				"5": "五等奖",
				"6": "六等奖",
				"7": "幸运奖",
				"8": "祝你好运",
			}
	   		$(".btn-saveAllOptions").on("click", function(e) {
	   			var allWrappers = $(".p-c-flexwrapper")
	   			var result = ""
	   			for (var i = 0; i < allWrappers.length; i++) {
	   				var $parent = $(allWrappers[i])
		   			var lotterPercent = $parent.find(".lotter-percent").val()
		   			/* if (!doubleNumberReg.test(lotterPercent)) {
		   				showNoticeModal("中奖几率输入有误")
		   				break
		   			}*/
		   			var maxMoney = $parent.find(".max-money") 
		   			/* if (maxMoney.length > 0 && !integerNumberReg.test(maxMoney.val()) && Number(maxMoney.val()) <= 99999) {
		   				showNoticeModal("最大金额输入有误")
		   				break	   				
		   			}  */
		   			var minMoney = $parent.find(".min-money") 
					/* if (minMoney.length > 0 && !integerNumberReg.test(minMoney.val())) {
		   				showNoticeModal("最小金额输入有误")
		   				break	   				
		   			}
		   			if (Number(minMoney.val()) > Number(maxMoney.val())) {
		   				showNoticeModal("最小金额不得大于最大金额")
		   				break
		   			} */
		   			var temp = ""
		   			 if ($parent.attr("data-index") === "8") {
		   				temp = "0,0," + lotterPercent + "," + "&"
		   			} else {
		   				temp = minMoney.val() + "," + maxMoney.val() + "," + lotterPercent + "," + "&"
		   			}
		   			result += temp
	   			}
				$.ajax({
					  url: "/activity/updateLuckyAttr.do",
					  type: "post",
					  data: {
						  lucky: result,
					  },
					  dataType: "json",
					  success:function(data){
						  if (data.message === "") {
							  showNoticeModal(data.data)
						  } else {
						  	  showNoticeModal("操作成功！")
						  }
					  },
				})	   			
	   		})
	   		$(".btn-bc").on("click",function(){
	   			$.ajax({
					  url: "/activity/updateUserLuckyCount.do",
					  type: "post",
					  data: {
						  name:$(".yhuming").val(),
						  count:$(".yaojiangcs").val(),
					  },
					  dataType: "json",
					  success:function(data){
						  if(data.data == 3){
							  showNoticeModal("用户不存在")
						  }
						  if(data.data == 2){
							  showNoticeModal("请填写用户名")
						  }
						  if(data.data == 1){
							  $(".btn-default").modal("hide")
							  showNoticeModal("操作成功")
						  }
						  if(data.data == 0){
							   showNoticeModal("操作失败")
						  }
						  if(data.data == 4){
							   showNoticeModal("请填需要修改的次数")
						  }
						  $("#addAndEditModal1").modal("hide");
					  },
				});	
	   		})
	</script>
</body>
</html>